<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="/static/common/taglib.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>密码设置</title>
    <%@include file="../../public/commonCss.jsp" %>
    <%@include file="../../public/commonJs.jsp" %>
</head>
<body>
<div id="wrapper">
    <div class="boxmain whiteBox lrbox">
        <div class="lrboxmain borderL" style="margin-left:0%">
            <div class="from-header borderB contentbox">
                <div>
                    <span class="font14"> 所属分类:</span><a id="category"><span class=" fontOrange2">密码修改</span></a>
                </div>
            </div>
            <div class="from-body withheader contentbox">
                <div class="layui-form layui-form-pane" style="margin-top:100px;margin-left:30%">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label" >原始密码：</label>
                            <div class="layui-input-block" style="width: 400px;">
                                <input type="password" name="password" required lay-verify="required"
                                       placeholder="请输入原始密码" class="layui-input"/>
                            </div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label" >请输入新密码：</label>
                            <div class="layui-input-inline">
                                <input type="password" name="newPwd" id="newPwd" lay-verify="pass" placeholder="请输入新密码"
                                       class="layui-input" style="border:1px solid #e6e6e6;"/>
                            </div>
                            <div class="layui-form-mid layui-word-aux">密码的长度在6-12位</div>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <label class="layui-form-label" >确认新密码：</label>
                        <div class="layui-input-block" style="width: 400px;">
                            <input type="password" name="newPwd2" lay-verify="regPwd" placeholder="确认新密码"
                                   class="layui-input"/>
                        </div>
                    </div>
                    <div class="layui-form-item">
                        <div class="layui-input-block">
                            <button class="layui-btn" lay-submit lay-filter="formDemo">保存</button>
                        </div>
                    </div>
                </div>

            </div>
        </div>
    </div>
    <!-- whitebox -->
</div>
<script type="text/javascript">
    var form = layui.form();
    //自定义验证规则
    form.verify({
        pass: [/(.+){6,12}$/, '密码必须6到12位'],
        content: function (value) {
            layedit.sync(editIndex);
        },
        regPwd: function (value) {
            //获取密码
            var pwd = $("#newPwd").val();
            if (!new RegExp(pwd).test(value)) {
                return '两次输入的密码不一致';
            }
        }
    });

    //监听提交
    form.on('submit(formDemo)', function (data) {
        //这里执行ajax提交
        $.ajax({
            type: 'post',
            url: '${ctx}/userController/modifyPassword.action',
            data: data.field,
            dataType: "json",
            timeout: 10000,
            success: function (data) {
                if (data.code == 0) {
                    layui.layer.alert('修改成功,请重新登录', {
                        btn: ['确定']
                    }, function () {
                        top.window.location.href = "${ctx}/logout.action";
                    });
                } else if (data.code == -2) {
                    parent.layer.msg('原始密码不正确', {icon: 2});
                } else if (data.code = -3) {
                    parent.layer.msg('旧密码和新密码不能相同', {icon: 2});
                } else if (data.code = -4) {
                    layui.layer.alert('登录超时，请重新登录', {
                        btn: ['确定']
                    }, function () {
                        top.window.location.href = "${ctx}/logout.action";
                    });
                }
            }
        });
        return false;
    });
    //关闭对话框
    form.render();
    function closeLayer() {
        parent.layer.close(index);
    }
</script>
</body>
</html>